package cn.springmvc.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.springmvc.model.Step1;
import cn.springmvc.model.Step2;
import cn.springmvc.model.Step3;
import cn.springmvc.model.Step4;
import cn.springmvc.model.Step5;
import cn.springmvc.model.Step6;
import cn.springmvc.model.Step7;
import cn.springmvc.model.Step8;
import cn.springmvc.service.Step1Service;
import cn.springmvc.service.Step2Service;
import cn.springmvc.service.Step3Service;
import cn.springmvc.service.Step4Service;
import cn.springmvc.service.Step5Service;
import cn.springmvc.service.Step6Service;
import cn.springmvc.service.Step7Service;
import cn.springmvc.service.Step8Service;

@Controller
public class MainController {
@Autowired
private Step1Service step1Service;
@Autowired
private Step2Service step2Service;
@Autowired
private Step3Service step3Service;
@Autowired
private Step4Service step4Service;
@Autowired
private Step5Service step5Service;
@Autowired
private Step6Service step6Service;
@Autowired
private Step7Service step7Service;
@Autowired
private Step8Service step8Service;
	@RequestMapping("/index")
	public String index(){
		//System.out.println(111);
		return "index";
	}
	@RequestMapping(value="/insertdatastep1",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData1(@RequestBody Step1 step1){
		Map<String, Object> ret=new HashMap<>();
		int year=step1.getNianfen();
		String name=step1.getName();
		Step1 st1=step1Service.getStep1ByNameAndNianfen(year, name);
		if (st1!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step1Service.insert(step1);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep2",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData2(@RequestBody Step2 step2){
		Map<String, Object> ret=new HashMap<>();
		int year=step2.getNianfen();
		String name=step2.getName();
		Step2 st2=step2Service.getStep2ByNameAndNianfen(year, name);
		if (st2!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step2Service.insert(step2);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep3",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData3(@RequestBody Step3 step3){
		Map<String, Object> ret=new HashMap<>();
		int year=step3.getNianfen();

		Step3 st3=step3Service.getStep3ByNianfen(year);
		if (st3!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step3Service.insert(step3);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep4",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData4(@RequestBody Step4 step4){
		Map<String, Object> ret=new HashMap<>();
		int year=step4.getNianfen();
		String name=step4.getName();
		Step4 st4=step4Service.getStep4ByNameAndNianfen(year, name);
		if (st4!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step4Service.insert(step4);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep5",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData5(@RequestBody Step5 step5){
		Map<String, Object> ret=new HashMap<>();
		int year=step5.getNianfen();
		String name=step5.getName();
		Step5 st5=step5Service.getStep5ByNameAndNianfen(year, name);
		if (st5!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step5Service.insert(step5);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep6",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData6(@RequestBody Step6 step6){
		Map<String, Object> ret=new HashMap<>();
		int year=step6.getNianfen();
		String name=step6.getName();
		Step6 st6=step6Service.getStep6ByNameAndNianfen(year, name);
		if (st6!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step6Service.insert(step6);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep7",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData7(@RequestBody Step7 step7){
		Map<String, Object> ret=new HashMap<>();
		int year=step7.getNianfen();
		String name=step7.getName();
		Step7 st7=step7Service.getStep7ByNameAndNianfen(year, name);
		if (st7!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step7Service.insert(step7);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/insertdatastep8",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object insertData8(@RequestBody Step8 step8){
		Map<String, Object> ret=new HashMap<>();
		int year=step8.getNianfen();
		String name=step8.getName();
		Step8 st8=step8Service.getStep8ByNameAndNianfen(year, name);
		if (st8!=null) {
			ret.put("message", "data exist!");
			return ret;
		}
		int tmpData=step8Service.insert(step8);
		if (tmpData==1) {
			ret.put("message", "success");
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep1s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep1s(@RequestBody Map<String, Object> args) throws ParseException{
		Map<String, Object> ret=new HashMap<>();
	//	String name=(String) args.get("name");
		String year=(String) args.get("year");
		List<Step1> lStep1s=step1Service.getStep1ByNianfen(Integer.parseInt(year));
		if (lStep1s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep1s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep2s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep2s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step2> lStep2s=step2Service.getStep2ByNianfen(year);
		if (lStep2s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep2s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep3s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep3s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		Step3 lStep3s=step3Service.getStep3ByNianfen(year);
		if (lStep3s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep3s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep4s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep4s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step4> lStep4s=step4Service.getStep4ByNianfen(year);
		if (lStep4s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep4s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep5s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep5s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step5> lStep5s=step5Service.getStep5ByNianfen(year);
		if (lStep5s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep5s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep6s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep6s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step6> lStep6s=step6Service.getStep6ByNianfen(year);
		if (lStep6s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep6s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep7s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep7s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step7> lStep7s=step7Service.getStep7ByNianfen(year);
		if (lStep7s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep7s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}
	@RequestMapping(value="/getStep8s",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	@ResponseBody
	public Object getStep8s(@RequestBody Map<String, Object> args){
		Map<String, Object> ret=new HashMap<>();
		//String name=(String) args.get("name");
		int year=Integer.parseInt((String) args.get("year"));
		List<Step8> lStep8s=step8Service.getStep8ByNianfen(year);
		if (lStep8s!=null) {
			ret.put("message", "success");
			ret.put("data", lStep8s);
		}
		else {
			ret.put("message", "failure");
		}
		return ret;
	}

}
